
import os


filePath='/home/lichaopeng/LCP_WORK_FILES/General_Recorder/Application/sata_sim_14/sata_sim_14.sim/sim_1/behav/compile.sh'

filePath2='/home/lichaopeng/LCP_WORK_FILES/General_Recorder/Application/sata_sim_14/sata_sim_14.sim/sim_1/behav/filelist2.txt'

f2=open(filePath2, 'w')


line_start=24
line_end = 83


file_path_list=[]
dir_list=[]
with open(filePath, 'r') as f:
	lines=f.readlines()
	for i in range(0, len(lines)):
		if i>=line_start-1 and i<=line_end-1:
			arrys=lines[i].split(" ")
			for item in arrys:
				if item.find("+incdir+")!=-1:
					include_dir = item.replace('+incdir+',"")
					if include_dir not in dir_list:
						dir_list.append(include_dir)
						#print(include_dir)
				elif item.find("$origin_dir")!=-1:
					filepath=item.replace("$origin_dir",".")
					
					print(filepath)
					f2.write(filepath+'\n')

	for item in dir_list:
		print(item)
		filedir=item.replace("$origin_dir",".")
		for root, dirs, files in os.walk(filedir):
			print(files)
			for filepath_inc in files:
				f2.write(filedir+'/'+filepath_inc+'\n') 	
			#print(arrys[6])
			#filepath=arrys[6]
			#filepath=filepath.replace("$origin_dir",".")
			#filepath=filepath.replace('"',"")
			#filepath=filepath.replace('+incdir+',"")

			#print(filepath)
			#f2.write(filepath+'\n')

f2.close()
